package com.pri.chat.activity;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.netease.nim.uikit.common.util.string.StringUtil;
import com.netease.nim.uikit.net.SharedHelper;
import com.netease.nim.uikit.net.entity.BaseBean;
import com.netease.nim.uikit.net.entity.JJBean;
import com.netease.nim.uikit.net.entity.MemberBean;
import com.netease.nim.uikit.net.entity.TiXianBean;
import com.netease.nim.uikit.net.entity.WalletResult;
import com.netease.nim.uikit.net.rxjava.HttpMethods;
import com.netease.nim.uikit.net.subscribers.ProgressSubscriber;
import com.netease.nim.uikit.net.subscribers.SubscriberOnNextListener;
import com.pri.chat.R;
import com.pri.chat.adapter.TiXianBeanAdapter;
import com.pri.chat.base.BaseActivity;
import com.pri.chat.base.TcWebActivity;
import com.pri.chat.dialog.DialogUtil;
import com.pri.chat.model.ConfirmTxModel;
import com.pri.chat.model.TxMsgModel;
import com.pri.chat.model.UserModel;
import com.pri.chat.utils.Des3Util;
import com.pri.chat.utils.GlideUtil;
import com.pri.chat.utils.StringUtils;
import com.pri.chat.view.ImageViewPlus;
import com.vondear.rxtool.RxActivityTool;
import com.vondear.rxtool.view.RxToast;
import com.vondear.rxui.view.dialog.RxDialogJBSureCancel;
import com.vondear.rxui.view.dialog.RxDialogSex;
import com.vondear.rxui.view.dialog.RxDialogZfb;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * 描述：添加类的描述
 *
 * @author wx5e48d604c2885118
 * @time 2020/4/23
 */
public class WalletActivity extends BaseActivity {
    @BindView(R.id.rx_progress)
    TextView rxProgress;
    @BindView(R.id.tv_jj_dh)
    TextView tvJjDh;
    @BindView(R.id.goldMoney)
    TextView goldMoney;
    @BindView(R.id.tixianNoteBtn)
    TextView tixianNoteBtn;
    @BindView(R.id.hongbaoMoney)
    TextView hongbaoMoney;
    @BindView(R.id.hongbaoShare)
    View hongbaoShare;
    @BindView(R.id.tv_play_game)
    TextView tvPlayGame;
    @BindView(R.id.wxRelation)
    View wxRelation;
    @BindView(R.id.wxImage)
    ImageView wxImage;
    @BindView(R.id.zfbRelation)
    View zfbRelation;
    @BindView(R.id.zfbImage)
    ImageView zfbImage;


    @BindView(R.id.ywjjLabel)
    TextView ywjjLabel;
    @BindView(R.id.ywjjMoney)
    TextView ywjjMoney;
    @BindView(R.id.ywjjRelation)
    View ywjjRelation;
    @BindView(R.id.ywjjTxMoney)
    TextView ywjjTxMoney;
    @BindView(R.id.ywjjImage)
    ImageView ywjjImage;

    @BindView(R.id.xrhbLabel)
    TextView xrhbLabel;
    @BindView(R.id.xrhbMoney)
    TextView xrhbMoney;
    @BindView(R.id.xrhbRelation)
    View xrhbRelation;
    @BindView(R.id.xrhbtxMoney)
    TextView xrhbtxMoney;
    @BindView(R.id.xrhbImage)
    ImageView xrhbImage;

    @BindView(R.id.svipLabel)
    TextView svipLabel;
    @BindView(R.id.svipMoney)
    TextView svipMoney;
    @BindView(R.id.svipRelation)
    View svipRelation;
    @BindView(R.id.svipTxMoney)
    TextView svipTxMoney;
    @BindView(R.id.svipImage)
    ImageView svipImage;

    @BindView(R.id.rec_main)
    RecyclerView recMain;

    @BindView(R.id.tv_tixian)
    TextView tv_tixian;
    @BindView(R.id.goldLabel)
    TextView goldLabel;

    @BindView(R.id.cgtxView)
    View cgtxView;
    @BindView(R.id.cgtxTitle)
    TextView cgtxTitle;

    @BindView(R.id.inviteLinear)
    View inviteLinear;
    @BindView(R.id.inviteTv)
    TextView inviteTv;
    @BindView(R.id.inviteImage)
    ImageViewPlus inviteImage;
    @BindView(R.id.inviteName)
    TextView inviteName;
    @BindView(R.id.tv_unit)
    TextView tvUnit;
    @BindView(R.id.ywjjShuoMing)
    TextView ywjjShuoMing;
    @BindView(R.id.jbShuoMing)
    TextView jbShuoMing;





    private int txType = -1; //0--现金红包；1--愿望基金；2--金币；3--超级VIP收益
    private int http_type;
    private int tiXianToAccount = 0; // 0--支付宝；1--微信

    private String inviteMemberId;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_wallet_layout;
    }

    @Override
    protected void initView() {
        inviteMemberId = SharedHelper.readValueByKeyForString(mContext,"sjId");
        if(StringUtil.isEmpty(inviteMemberId)){
            inviteTv.setVisibility(View.VISIBLE);
            inviteName.setVisibility(View.GONE);
            inviteImage.setVisibility(View.GONE);
        }else{
            getMemberInfoByMemberId();
        }
        String sex = SharedHelper.readSex(mContext);
//        if (!"女".equals(sex)) {
//            tixianNoteBtn.setText("去充值");
//        }
        setTitle("我的钱包");
        btnRight.setText("清单");
        if(SharedHelper.readSex(mContext).equals("女")){
            goldLabel.setText("火力值");
            tvUnit.setText("火力");
            jbShuoMing.setText("什么是火力值？");
        }else{
            goldLabel.setText("火苗币");
            tvUnit.setText("币");
            jbShuoMing.setText("什么是火苗币？");
        }
        btnRight.setTextColor(Color.parseColor("#666666"));
        btnRight.setBackgroundColor(Color.parseColor("#FFFFFF"));
        btnRight.setVisibility(View.VISIBLE);

        btnRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RxActivityTool.skipActivity(mContext,QingDanActivity.class);
            }
        });
        initRv();
        if(SharedHelper.readSex(mContext).equals("男")){
            recMain.setVisibility(View.GONE);
            cgtxTitle.setVisibility(View.GONE);
            cgtxView.setVisibility(View.GONE);
        }
        initRxDialog();
        httpGetJJ();
    }

    private List<TiXianBean> mList;
    private TiXianBeanAdapter mAdapter;
    private int mPosition = -1;

    private void initRv() {
        mList = new ArrayList<>();
        GridLayoutManager linearLayoutManager = new GridLayoutManager(this, 3);
        recMain.setLayoutManager(linearLayoutManager);
        mAdapter = new TiXianBeanAdapter(R.layout.item_tixian, mList);
        recMain.setAdapter(mAdapter);
        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            mPosition = position;
            for (int i = 0; i < mList.size(); i++) {
                if (i == position) {
                    mList.get(position).setCheck(true);
                } else {
                    mList.get(i).setCheck(false);
                }
            }
            mAdapter.notifyDataSetChanged();

            //0--现金红包；1--愿望基金；2--金币；3--超级VIP收益
            txType = 2;
            ywjjRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
            ywjjImage.setVisibility(View.GONE);
            ywjjLabel.setTextColor(getResources().getColor(R.color.color_333333));
            ywjjTxMoney.setTextColor(getResources().getColor(R.color.color_333333));

            xrhbRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
            xrhbImage.setVisibility(View.GONE);
            xrhbLabel.setTextColor(getResources().getColor(R.color.color_333333));
            xrhbtxMoney.setTextColor(getResources().getColor(R.color.color_333333));

            svipRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
            svipImage.setVisibility(View.GONE);
            svipLabel.setTextColor(getResources().getColor(R.color.color_333333));
            svipTxMoney.setTextColor(getResources().getColor(R.color.color_333333));
        });
        txType = 0;
        xrhbRelation.setBackgroundResource(R.drawable.btn_orange_noconer_line_shape);
        xrhbImage.setVisibility(View.VISIBLE);
        xrhbLabel.setTextColor(getResources().getColor(R.color.color_333333));
        xrhbtxMoney.setTextColor(getResources().getColor(R.color.color_333333));
    }

    @Override
    protected void initData() {
        SubscriberOnNextListener<BaseBean<WalletResult>> onNextListener = baseBean -> {
            mList.clear();
            mList.addAll(baseBean.getData().getList());
            mAdapter.notifyDataSetChanged();
            goldMoney.setText(baseBean.getData().getGoldNumber());
            hongbaoMoney.setText(baseBean.getData().getXinrenHongBao());
            ywjjMoney.setText(baseBean.getData().getYyjjMoney());
            ywjjTxMoney.setText(baseBean.getData().getYyjjMoney() + "元");
            xrhbMoney.setText(baseBean.getData().getXinrenHongBao());
            xrhbtxMoney.setText(baseBean.getData().getXinrenHongBao() + "元");
            svipMoney.setText(baseBean.getData().getSuperVipMoney());
            svipTxMoney.setText(baseBean.getData().getSuperVipMoney() + "元");

        };
        Map<String, Object> params = new HashMap<>();
        params.put("memberId", SharedHelper.readId(this));
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), Des3Util.getJiaMi(params));
        HttpMethods.getInstance().listTiXianItem(new ProgressSubscriber<>(onNextListener, this, true), requestBody);
    }

    private RxDialogZfb rxDialogZfb;
    private void initSexDialog() {
        rxDialogZfb = new RxDialogZfb(this);
        rxDialogZfb.setSureListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rxDialogZfb.dismiss();
                if(StringUtils.isEmpty(rxDialogZfb.getNameEdit().getText().toString())){
                    RxToast.normal("请输入您的姓名");
                    return ;
                }
                if(StringUtils.isEmpty(rxDialogZfb.getAccountEdit().getText().toString())){
                    RxToast.normal("请输入您的账号");
                    return ;
                }
                tixian();
            }
        });
        rxDialogZfb.setCancelListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rxDialogZfb.dismiss();
            }
        });
        rxDialogZfb.getAccountEdit().setText("");
        rxDialogZfb.getNameEdit().setText("");
        rxDialogZfb.show();
    }

    private void tixian() {
        SubscriberOnNextListener<BaseBean> onNextListener = baseBean -> {
            RxToast.normal("保存成功");
            SharedHelper.saveKeyValueForString(mContext,"trueName",rxDialogZfb.getNameEdit().toString());
            SharedHelper.saveKeyValueForString(mContext,"zfbNo",rxDialogZfb.getAccountEdit().toString());
        };
        TxMsgModel regModel = new TxMsgModel();//登录上传参数
        regModel.setId(SharedHelper.readId(this));
        regModel.setTrueName(rxDialogZfb.getNameEdit().getText().toString());
        regModel.setZfbNo(rxDialogZfb.getAccountEdit().getText().toString());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), Des3Util.getJiaMi(regModel));
        HttpMethods.getInstance().updateTiXianInfo(new ProgressSubscriber<>(onNextListener, this, true), requestBody);
    }


    /**
     * @param money
     */
    private void httpTX(String money) {
        SubscriberOnNextListener<BaseBean> onNextListener = baseBean -> {
            if(!baseBean.isSuccess()){
                RxToast.normal(baseBean.getMsg());
                if(baseBean.getMsg().equals("请维护支付宝提现账号！")){
                    initSexDialog();
                }
                return;
            }
            RxToast.normal(baseBean.getMsg());
            initData();
        };
        ConfirmTxModel regModel = new ConfirmTxModel();//登录上传参数
        regModel.setMemberId(SharedHelper.readId(this));
        regModel.setTxMoney(money);
        regModel.setTxType(txType);
        regModel.setType(tiXianToAccount);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), Des3Util.getJiaMi(regModel));
        HttpMethods.getInstance().tiXian(new ProgressSubscriber<>(onNextListener, this, true), requestBody);
    }

    private void dh() {
        SubscriberOnNextListener<BaseBean<JJBean>> onNextListener = baseBean -> {
            if (timer != null) {
                timer.cancel();
            }
            httpGetJJ();
            initData();
        };
        UserModel userModel = new UserModel();
        userModel.setMemberId(SharedHelper.readId(mContext));
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), Des3Util.getJiaMi(userModel));
        HttpMethods.getInstance().duiHuanYyjj(new ProgressSubscriber<>(onNextListener, mContext, false), requestBody);

    }

    BigDecimal mMoney = new BigDecimal("0.000000");
    BigDecimal mMin = new BigDecimal("0.000001");
    BigDecimal mDay = new BigDecimal("0.1");
    private int MAX_TIMER = 86400;
    BigDecimal timer_2;
    private int count_time;

    private boolean isFinish = false;
    private CountDownTimer timer;
    private void httpGetJJ() {
        SubscriberOnNextListener<BaseBean<JJBean>> onNextListener = baseBean -> {
            if(Double.parseDouble(baseBean.getData().getYyjjMoney())>=50d){
                rxProgress.setText("0.0");
            }else{
                BigDecimal timer_1;
                if(Double.parseDouble(baseBean.getData().getYyjjMoney())<49d){
                    timer_1 = new BigDecimal(baseBean.getData().getTimer()).divide(new BigDecimal(1000000));
                    timer_2 = new BigDecimal(baseBean.getData().getBegin()).divide(new BigDecimal(10));
                }else{
                    mMoney = new BigDecimal("0.0000000");
                    mMin = new BigDecimal("0.0000001");
                    mDay = new BigDecimal("0.01");

                    timer_1 = new BigDecimal(baseBean.getData().getTimer()).divide(new BigDecimal(10000000));
                    timer_2 = new BigDecimal(baseBean.getData().getBegin()).divide(new BigDecimal(100));
                }
                mMoney = timer_1;
                count_time = MAX_TIMER - baseBean.getData().getTimer();
                if (!baseBean.getData().getBegin().equals("2")) {
                    rxProgress.setText(mMoney.add(timer_2).toPlainString());
                    countDown();
                    timer.start();
                } else {
                    rxProgress.setText(timer_2.toPlainString());
                }
            }
        };
        UserModel userModel = new UserModel();
        userModel.setMemberId(SharedHelper.readId(mContext));
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), Des3Util.getJiaMi(userModel));
        HttpMethods.getInstance().getYwjjInfo(new ProgressSubscriber<>(onNextListener, mContext, false), requestBody);
    }


    @OnClick({R.id.jbShuoMing,R.id.ywjjShuoMing, R.id.tv_jj_dh,R.id.tv_play_game,R.id.inviteLinear,R.id.inviteImage,R.id.inviteName,R.id.hongbaoShare, R.id.tixianNoteBtn, R.id.tv_tixian, R.id.wxRelation, R.id.zfbRelation, R.id.ywjjRelation, R.id.svipRelation, R.id.xrhbRelation})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.jbShuoMing:
                Intent intent = new Intent();
                intent.setClass(mContext, TcWebActivity.class);
                if("什么是火苗币？".equals(jbShuoMing.getText().toString())){
                    intent.putExtra("title","火苗币说明");
                    intent.putExtra("url", HttpMethods.BASE_URL+"p/front_editorHtmlShow.html?code=huoMiaoBiCode");
                }else{
                    intent.putExtra("title","火力值说明");
                    intent.putExtra("url", HttpMethods.BASE_URL+"p/front_editorHtmlShow.html?code=huoLiZhiCode");
                }
                startActivity(intent);
                break;
            case R.id.ywjjShuoMing:
                Intent intent1 = new Intent();
                intent1.setClass(mContext, TcWebActivity.class);
                intent1.putExtra("title","愿望金说明");
                intent1.putExtra("url", HttpMethods.BASE_URL+"p/front_editorHtmlShow.html?code=yuanwangjijinCode");
                startActivity(intent1);
                break;
            case R.id.tv_jj_dh:
                dh();
                break;
            case R.id.tv_play_game:
                RxActivityTool.skipActivity(mContext, PlayGameActivity.class);
                break;
            case R.id.inviteLinear:
                if(!StringUtil.isEmpty(inviteMemberId)){
                    return;
                }
                rxDialogEditSureCancel.show();
                break;
            case R.id.inviteImage:
            case R.id.inviteName:
                Bundle bundle = new Bundle();
                bundle.putString("id", inviteMemberId);
                RxActivityTool.skipActivity(mContext, OtherPeopleMsgActivity.class, bundle);
                break;
            case R.id.hongbaoShare:
                initShareDialog("");
                break;
            case R.id.tixianNoteBtn:
                if (tixianNoteBtn.getText().toString().equals("去充值")) {
                    RxActivityTool.skipActivityForResult(this, TiXianNoteListActivity.class, 2);
                } else {
                    //提现记录
                    RxActivityTool.skipActivity(this, TiXianNoteListActivity.class);
                }
                break;
            case R.id.tv_tixian:
//                if(SharedHelper.readMobile(this).isEmpty()){
//                    RxToast.normal("请先到设置里边绑定手机号，然后进行提现！");
//                    RxActivityTool.skipActivity(mContext,BindMobieActivity.class);
//                    return;
//                }
//                if(StringUtil.isEmpty(SharedHelper.readValueByKeyForString(mContext,"zfbNo")) && tiXianToAccount==0){
//                    RxToast.normal("请先维护支付宝提现账号，然后进行提现！");
//                    RxActivityTool.skipActivity(mContext,AddTxActivity.class);
//                    return;
//                }
//                if(StringUtil.isEmpty(SharedHelper.readValueByKeyForString(mContext,"wxNo")) && tiXianToAccount==1){
//                    RxToast.normal("请先维护微信提现账号，然后进行提现！");
//                    RxActivityTool.skipActivity(mContext,AddTxActivity.class);
//                    return;
//                }
                //0--现金红包；1--愿望基金；2--金币；3--超级VIP收益
                String money = "0";
                if (txType == -1) {
                    RxToast.normal("请选择提现种类！");
                    return;
                } else if (txType == 2) {
                    //提现金币
                    if (mPosition == -1) {
                        RxToast.normal("请选择提现金额！");
                        return;
                    }
                    money = mList.get(mPosition).getId();
                } else if (txType == 1) {
                    if(Double.parseDouble(ywjjMoney.getText().toString())<50d){
                        RxToast.normal("愿望金满50可提现！");
                        return;
                    }
                    money = "50";
                } else if (txType == 0) {
                    money = xrhbMoney.getText().toString();
                    if(Double.parseDouble(money) == 0d){
                        RxToast.normal("金额不足！");
                        return;
                    }
                } else if (txType == 3) {
                    money = xrhbMoney.getText().toString();
                    if(Double.parseDouble(money) == 0d){
                        RxToast.normal("金额不足！");
                        return;
                    }
                }

                httpTX(money);
                break;
            case R.id.wxRelation:
                RxToast.normal("微信提现暂未开放！");
//                tiXianToAccount = 1;
//                wxRelation.setBackgroundResource(R.drawable.btn_orange_noconer_line_shape);
//                wxImage.setVisibility(View.VISIBLE);
//                zfbRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
//                zfbImage.setVisibility(View.GONE);
                break;
            case R.id.zfbRelation:
                tiXianToAccount = 0;
                wxRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
                wxImage.setVisibility(View.GONE);
                zfbRelation.setBackgroundResource(R.drawable.btn_orange_noconer_line_shape);
                zfbImage.setVisibility(View.VISIBLE);
                break;
            case R.id.ywjjRelation:
                //0--现金红包；1--愿望基金；2--金币；3--超级VIP收益
                txType = 1;
                ywjjRelation.setBackgroundResource(R.drawable.btn_orange_noconer_line_shape);
                ywjjImage.setVisibility(View.VISIBLE);
                ywjjLabel.setTextColor(getResources().getColor(R.color.orange));
                ywjjTxMoney.setTextColor(getResources().getColor(R.color.orange));

                xrhbRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
                xrhbImage.setVisibility(View.GONE);
                xrhbLabel.setTextColor(getResources().getColor(R.color.color_333333));
                xrhbtxMoney.setTextColor(getResources().getColor(R.color.color_333333));


                svipRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
                svipImage.setVisibility(View.GONE);
                svipLabel.setTextColor(getResources().getColor(R.color.color_333333));
                svipTxMoney.setTextColor(getResources().getColor(R.color.color_333333));


                if (mPosition >= 0) {
                    mList.get(mPosition).setCheck(false);
                    mAdapter.notifyDataSetChanged();
                    mPosition = -1;
                }

                break;
            case R.id.xrhbRelation:
                //0--现金红包；1--愿望基金；2--金币；3--超级VIP收益
                txType = 0;
                ywjjRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
                ywjjImage.setVisibility(View.GONE);
                ywjjLabel.setTextColor(getResources().getColor(R.color.color_333333));
                ywjjTxMoney.setTextColor(getResources().getColor(R.color.color_333333));

                xrhbRelation.setBackgroundResource(R.drawable.btn_orange_noconer_line_shape);
                xrhbImage.setVisibility(View.VISIBLE);
                xrhbLabel.setTextColor(getResources().getColor(R.color.orange));
                xrhbtxMoney.setTextColor(getResources().getColor(R.color.orange));

                svipRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
                svipImage.setVisibility(View.GONE);
                svipLabel.setTextColor(getResources().getColor(R.color.color_333333));
                svipTxMoney.setTextColor(getResources().getColor(R.color.color_333333));

                if (mPosition >= 0) {
                    mList.get(mPosition).setCheck(false);
                    mAdapter.notifyDataSetChanged();
                    mPosition = -1;
                }

                break;
            case R.id.svipRelation:
                //0--现金红包；1--愿望基金；2--金币；3--超级VIP收益
                txType = 3;
                ywjjRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
                ywjjImage.setVisibility(View.GONE);
                ywjjLabel.setTextColor(getResources().getColor(R.color.color_333333));
                ywjjTxMoney.setTextColor(getResources().getColor(R.color.color_333333));

                xrhbRelation.setBackgroundResource(R.drawable.btn_gray_noconer_line_shape);
                xrhbImage.setVisibility(View.GONE);
                xrhbLabel.setTextColor(getResources().getColor(R.color.color_333333));
                xrhbtxMoney.setTextColor(getResources().getColor(R.color.color_333333));

                svipRelation.setBackgroundResource(R.drawable.btn_orange_noconer_line_shape);
                svipImage.setVisibility(View.VISIBLE);
                svipLabel.setTextColor(getResources().getColor(R.color.orange));
                svipTxMoney.setTextColor(getResources().getColor(R.color.orange));

                if (mPosition >= 0) {
                    mList.get(mPosition).setCheck(false);
                    mAdapter.notifyDataSetChanged();
                    mPosition = -1;
                }

                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

    private void countDown() {
        timer = new CountDownTimer(count_time * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                mMoney = mMoney.add(mMin);
                rxProgress.setText(mMoney.add(timer_2).toPlainString());
            }

            @Override
            public void onFinish() {
                if (!isFinish) {
                    mMoney = mDay;
                    rxProgress.setText(mMoney.add(timer_2).toPlainString());
                    count_time = MAX_TIMER;
                    timer.start();
                }
            }
        };


    }

    private Dialog mShareDialog;

    private void initShareDialog(String path) {
        mShareDialog = DialogUtil.getInstance().showShareDialog(activity, 0);
        DialogUtil.getInstance().setOnShareClickListener(new DialogUtil.OnShareClickListener() {
            @Override
            public void qqOnClick(View v) {

            }

            @Override
            public void circleOnClick(View v) {
                mShareDialog.dismiss();
                DialogUtil.getInstance().shareWechatMoments(path,HttpMethods.SHARE_TITLE,"我领了5块钱，你也来领红包吧！",HttpMethods.SHARE_URL);
            }

            @Override
            public void qZoneOnClick(View v) {

            }

            @Override
            public void weixinOnClick(View v) {
                mShareDialog.dismiss();
                DialogUtil.getInstance().shareWeChat(path,HttpMethods.SHARE_TITLE,"我领了5块钱，你也来领红包吧！",HttpMethods.SHARE_URL);
            }

            @Override
            public void jubaoOnClick(View v) {

            }
        });
        mShareDialog.show();
    }


    RxDialogJBSureCancel rxDialogEditSureCancel;
    private void initRxDialog() {
        rxDialogEditSureCancel = new RxDialogJBSureCancel(this);
        rxDialogEditSureCancel.getTitleView().setText("填写邀请码");
        rxDialogEditSureCancel.getEditText().setHint("请输入邀请码");
        rxDialogEditSureCancel.getCancelView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rxDialogEditSureCancel.dismiss();
            }
        });
        rxDialogEditSureCancel.getSureView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                rxDialogEditSureCancel.dismiss();
                if (getString(rxDialogEditSureCancel.getEditText()).isEmpty()) {
                    RxToast.normal("请输入邀请码");
                    return;
                }
                httpSet();
            }


        });
    }
    private void httpSet() {
        SubscriberOnNextListener<BaseBean<String>> onNextListener = baseBean -> {
            RxToast.normal(baseBean.getMsg());
            inviteMemberId = baseBean.getData();
            SharedHelper.saveKeyValueForString(mContext,"sjId",baseBean.getData());
            rxDialogEditSureCancel.getEditText().setText("");
            getMemberInfoByMemberId();
        };
        Map<String,Object> params = new HashMap<>();
        params.put("memberId",SharedHelper.readId(this));
        params.put("code",rxDialogEditSureCancel.getEditText().getText().toString());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), Des3Util.getJiaMi(params));
        HttpMethods.getInstance().bindCode(new ProgressSubscriber<>(onNextListener, this, false), requestBody);
    }

    private void getMemberInfoByMemberId() {
        SubscriberOnNextListener<BaseBean<MemberBean>> onNextListener = baseBean -> {
            inviteTv.setVisibility(View.INVISIBLE);
            inviteName.setVisibility(View.VISIBLE);
            inviteName.setText(baseBean.getData().getName());
            inviteImage.setVisibility(View.VISIBLE);
            GlideUtil.getInstance().loadHeadImg(mContext,inviteImage,baseBean.getData().getHeadPic());
        };
        Map<String,Object> reqObj = new HashMap<>();
        reqObj.put("memberId", inviteMemberId);
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), Des3Util.getJiaMi(reqObj));
        HttpMethods.getInstance().getMemberInfoByMemberId(new ProgressSubscriber<>(onNextListener, mContext, false), requestBody);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(timer != null){
            timer.cancel();
        }
    }
}
